package com.omg.api.entry;

import javax.servlet.http.HttpServletRequest;

import com.omg.api.argument.Argument;
import com.omg.api.argument.LoginArgument;
import com.omg.api.handle.LoginHandler;
import com.omg.constant.ResponseCode;

/**
 * 
 * @author xiazhiquan
 * 
 *         May 28, 2011
 */
public class login extends Entry {

	private static final long serialVersionUID = 1L;

	public login() {
		super(false);
	}

	@Override
	protected Argument fetchArgument(HttpServletRequest request)
			throws Exception {
		// email
		String email = request.getParameter("email");

		if (email == null || email.isEmpty()) {
			throw new Exception("" + ResponseCode.AP_E_Info_EmailInvalid);
		}

		// passwd
		String passwd = request.getParameter("passwd");
		if (passwd == null || passwd.isEmpty()) {
			throw new Exception("" + ResponseCode.AP_E_Info_PasswordMissing);
		}

		// generate argument
		LoginArgument loginArgument = new LoginArgument();
		loginArgument.setEmail(email);
		loginArgument.setPasswd(passwd);

		return loginArgument;
	}

	@Override
	protected String getResult(Argument argument) throws Exception {
		return LoginHandler.getInstance().handle(argument);
	}

}
